package com.certification.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.certification.common.utils.Constant;
import com.certification.entity.ProfessionSelfEvaluation;
import com.certification.service.ProfessionSelfEvaluationService;
import com.certification.service.SysUserRoleService;
import com.certification.vo.PageVO;
import com.certification.vo.ResponseMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author copa
 * @createDate 2022-03-29 21:16
 * @function
 */
@RestController
@Api(tags = {"流程：专业自评"})
public class ProfessionSelfEvaluationController extends AbstractController {

    @Resource
    private ProfessionSelfEvaluationService professionSelfEvaluationService;

    @Resource
    private SysUserRoleService sysUserRoleService;

    @GetMapping("admin/proDetailPage/{certId}")
    @ApiOperation(value = "查看专业自评分页（认证专家）")
    public ResponseMessage<Page<ProfessionSelfEvaluation>> getProDetailAdminPage(@PathVariable Integer certId, PageVO pageVO) {
        for (Long roleId : sysUserRoleService.queryRoleIdList(getUser().getUserId())) {
            if (roleId == Constant.ROLE_EXPERT) {
                return professionSelfEvaluationService.getProDetailAdminPage(certId, pageVO);
            }
        }
        return ResponseMessage.errorMsg("该角色不能调用该接口~");
    }

    @GetMapping("admin/proDetail/{certId}/{proId}")
    @ApiOperation(value = "查看详细认证（认证专家）")
    public ResponseMessage<ProfessionSelfEvaluation> getProDetailAdmin(@PathVariable("certId") Integer certId,
            @PathVariable("proId") Integer proId) {
        for (Long roleId : sysUserRoleService.queryRoleIdList(getUser().getUserId())) {
            if (roleId == Constant.ROLE_EXPERT) {
                return professionSelfEvaluationService.getProDetailAdmin(certId, proId);
            }
        }
        return ResponseMessage.errorMsg("该角色不能调用该接口~");
    }
//    @GetMapping("admin/proDetail/{certId}")
//    @ApiOperation(value = "查看详细认证（认证专家）")
//    public ResponseMessage<ProfessionSelfEvaluation> getProDetailAdmin(@PathVariable Integer certId) {
//        for (Long roleId : sysUserRoleService.queryRoleIdList(getUser().getUserId())) {
//            if (roleId == Constant.ROLE_EXPERT) {
//                return professionSelfEvaluationService.getProDetailAdmin(certId);
//            }
//        }
//        return ResponseMessage.errorMsg("该角色不能调用该接口~");
//    }

    @PutMapping("admin/pro")
    @ApiOperation(value = "判定认证是否通过：第二阶段")
    public ResponseMessage<String> putProAdmin(@RequestParam @ApiParam("认证id") Integer certId,
                                 @RequestParam @ApiParam("同意-1 驳回-2") Integer status,
                                 @RequestParam(required = false) @ApiParam("驳回和同意写理由") String remark) {
        for (Long roleId : sysUserRoleService.queryRoleIdList(getUser().getUserId())) {
            if (roleId == Constant.ROLE_EXPERT) {
                return professionSelfEvaluationService.putProAdmin(certId, status, remark);
            }
        }
        return ResponseMessage.errorMsg("该角色不能调用该接口~");
    }

    @PostMapping("admin/pro/expertAdvice")
    @ApiOperation(value = "改进措施处理")
    public ResponseMessage<String> postExpertAdvice(@RequestParam @ApiParam("认证id") Integer certId,
                                                    @RequestParam @ApiParam("专业自评id") Integer proId,
                                                    @RequestParam @ApiParam("肯定-1 改进-2") Integer status,
                                                    @RequestParam(required = false) @ApiParam("改进措施") String expertAdvice) {
        for (Long roleId : sysUserRoleService.queryRoleIdList(getUser().getUserId())) {
            if (roleId == Constant.ROLE_EXPERT) {
                return professionSelfEvaluationService.postExpertAdvice(certId, proId, status, expertAdvice);
            }
        }
        return ResponseMessage.errorMsg("该角色不能调用该接口~");
    }

    @PutMapping("admin/pro/expertAdvice")
    @ApiOperation(value = "修改改进措施")
    public ResponseMessage<String> putExpertAdvice(@RequestParam @ApiParam("认证id") Integer certId,
                                                   @RequestParam @ApiParam("专业自评id") Integer proId,
                                     @RequestParam @ApiParam("改进措施") String expertAdvice) {
        for (Long roleId : sysUserRoleService.queryRoleIdList(getUser().getUserId())) {
            if (roleId == Constant.ROLE_EXPERT) {
                return professionSelfEvaluationService.putExpertAdvice(certId, proId, expertAdvice);
            }
        }
        return ResponseMessage.errorMsg("该角色不能调用该接口~");
    }

}
